package cobersky.skinUI.core
{
	import flash.display.Sprite;

	public class PageContainer extends Sprite
	{
		private var _pageElements:Vector.<Page>;
		private var _current:Page;
		private var _currentIndex:int;
		private var _roundMethod:Boolean;
		public function PageContainer(){
			_pageElements=new Vector.<Page>;
		}
		public function get roundMethod():Boolean{
			return _roundMethod;
		}
		public function set roundMethod(value:Boolean):void{
			_roundMethod = value;
		}
		public function addPage(pe:Page):void{
			_pageElements.push(pe);
		}
		public function removePage(pe:Page):void{
			removePageAt(_pageElements.indexOf(pe));
		}
		public function removePageAt(index:int):void{
			_pageElements.splice(index,1);
		}
		public function get numElements():int{
			return _pageElements.length;
		}
		public function goto(index:uint):void{
			
			if(_current)_current.dispose();
			_currentIndex=_roundMethod?index%numElements:Math.min(index,numElements-1);
			_current=_pageElements[_currentIndex];
			_current.create();
		}
		public function next():void{
			trace(_currentIndex);
			goto(++_currentIndex);
		}
		public function prev():void{
			goto(--_currentIndex);
		}
	}
}